package com.fs.sale.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fs.common.core.pojo.Customer;
import com.fs.sale.mapper.CustomerMapper;
import com.fs.sale.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    CustomerMapper customerMapper;

    @Override
    public List<Customer> selectAll() {
        return customerMapper.selectList(null);
    }

    @Override
    public List<Customer> query(Customer customer) {
        QueryWrapper<Customer> queryWrapper=new QueryWrapper<>();
        if(!StrUtil.isEmpty(customer.getAddress())){
            queryWrapper.like("address",customer.getAddress());
        }else if(!StrUtil.isEmpty(customer.getCustomerName())){
            queryWrapper.like("customer_name",customer.getCustomerName());
        }
        return customerMapper.selectList(queryWrapper);
    }

    @Override
    public int addCustomer(Customer customer) {
        return customerMapper.insert(customer);
    }

    @Override
    public int deleteCustomer(int id) {
        return customerMapper.deleteById(id);
    }

    public static void main(String[] args) {
        Integer i=0;


    }
}
